var url = ''
console.log(process.env.NODE_ENV)
if (process.env.NODE_ENV == 'development') {
	console.log('开发环境')
	url = 'http://localhost:8000'
} else {
	console.log('生产环境')
	// url = 'http://ssss.jj-ai.com/'
}
export const baseUrl = url

export function http(url, data, method = 'GET') {
	console.log('请求地址', url)
	console.log('请求参数', data)
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			data: data,
			header: {
				'content-type': 'application/x-www-form-urlencoded'
			},
			method,
			success: (res) => {
				if (res.statusCode == 200) {
					if (res.data.code == 200) {
						resolve(res.data)
					} else if (res.data.code == 0) {
						// uni.showToast({
						// 	title: res.data.msg,
						// 	icon: 'none'
						// })
						reject('服务器报错')
					}
				}
				console.log(res, '请求成功')
			},
			fail: (res) => {
				uni.showToast({
					title: '服务器请求异常',
					icon: 'none'
				})
			}
		})
	})
}
